﻿using Microsoft.AspNetCore.Mvc;
using Middleware.ApiTest.Attributes;
using Middleware.ApiTest.Services;
using Middleware.ApiTest.Services.Dtos;

namespace Middleware.ApiTest.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [ApiController]
    [Route("api/Order[controller]")]
    public class OrderController : ControllerBase
    {
        private readonly IOrderServices _OrderService;
        public OrderController(IOrderServices OrderService)
        {
            _OrderService = OrderService;
        }

        /// <summary>
        /// 获取订单列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        [DataMasking]
        public async Task<List<OrderInfoDto>> GetOrderListAsync()
        {
            var list = await _OrderService.GetOrderListAsync();
            return list;
        }

        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<string> CreateOrderAsync(CreateOrderDto dto)
        {
            var result = await _OrderService.CreateOrderAsync(dto);
            return result ?"创建成功":"创建失败";
        }

    }
}
